//
//  NewsFromViewController.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/6.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "NewsFromViewController.h"
#import "NewsChildFromViewController.h"
#import "NewsChildTwoFromViewController.h"

@interface NewsFromViewController ()<SGPageTitleViewDelegate, SGPageContentViewDelegate>
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentView *pageContentView;

@end

@implementation NewsFromViewController

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"消息";
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = YES; // 设置导航背景图片之后发生偏移，使用此属性回归正常
    
//    UIImage *barImage = [UIImage imageNamed:@"bg"];
    UIImageView *barImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg"]];
    barImage.contentMode = UIViewContentModeRedraw;
    [self.navigationController.navigationBar setBackgroundImage:barImage.image forBarMetrics:UIBarMetricsDefault];
    
//    UIImageView *navBarBgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 64)];
//    navBarBgImage.image = [UIImage imageNamed:@"bg"];
//    [self.navigationController.navigationBar sendSubviewToBack:navBarBgImage];
    
    
    self.navigationController.navigationBar.contentMode = UIViewContentModeScaleAspectFit;
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setShadowImage:nil];
    [self showNewsVC];
}

- (void)showNewsVC
{
    NewsChildFromViewController *childOne = [[NewsChildFromViewController alloc] init];
    NewsChildTwoFromViewController *childTwo = [[NewsChildTwoFromViewController alloc] init];
    
    NSArray *childArr = @[childOne, childTwo];
    
    /// pageContentView
    CGFloat contentViewHeight = self.view.frame.size.height - 108;
    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, 108, self.view.frame.size.width, contentViewHeight) parentVC:self childVCs:childArr];
    _pageContentView.delegatePageContentView = self;
    [self.view addSubview:_pageContentView];
    
    NSArray *titleArr = @[@"好友", @"私信"];
    /// pageTitleView
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 44) delegate:self titleNames:titleArr];
    [self.view addSubview:_pageTitleView];
    _pageTitleView.selectedIndex = 0;
    _pageTitleView.titleColorStateNormal = [UIColor lightGrayColor];
    _pageTitleView.titleColorStateSelected = [UIColor blackColor];
    _pageTitleView.indicatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fengetiaotwo"]];
    _pageTitleView.indicatorLengthStyle = SGIndicatorLengthStyleEqual;
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
}

- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
